########################################################
# HOOMD CMake configuration for externally built plugins

@PACKAGE_INIT@

include(CMakeFindDependencyMacro)

# build options
set(HOOMD_SHORTREAL_SIZE "@HOOMD_SHORTREAL_SIZE@")
set(HOOMD_LONGREAL_SIZE "@HOOMD_LONGREAL_SIZE@")
set(HOOMD_GPU_PLATFORM "@HOOMD_GPU_PLATFORM@")

set(BUILD_MD "@BUILD_MD@")
set(BUILD_HPMC "@BUILD_HPMC@")
set(BUILD_METAL "@BUILD_METAL@")
set(BUILD_DEM "@BUILD_DEM@")
set(BUILD_MPCD "@BUILD_MPCD@")

set(ENABLE_HIP "@ENABLE_HIP@")
set(HIP_PLATFORM "@HIP_PLATFORM@")
set(ENABLE_ROCTRACER "@ENABLE_ROCTRACER@")
set(ENABLE_MPI "@ENABLE_MPI@")
set(ALWAYS_USE_MANAGED_MEMORY "@ALWAYS_USE_MANAGED_MEMORY@")

# CUDA architectures
set(CMAKE_CUDA_ARCHITECTURES "@CMAKE_CUDA_ARCHITECTURES@")

# C++ standard
set(CMAKE_CXX_STANDARD "@CMAKE_CXX_STANDARD@")
set(CMAKE_CUDA_STANDARD "@CMAKE_CUDA_STANDARD@")

# installation locations
set(HOOMD_INSTALL_PREFIX "@PACKAGE_CMAKE_INSTALL_PREFIX@")
set(PYTHON_SITE_INSTALL_DIR "@PYTHON_SITE_INSTALL_DIR@")

# configure python
set(Python_FIND_UNVERSIONED_NAMES "FIRST")
find_package(Python REQUIRED COMPONENTS Interpreter Development)
find_package(pybind11 2.12 CONFIG REQUIRED)
find_package_message(pybind11 "Found pybind11: ${pybind11_DIR} ${pybind11_INCLUDE_DIR} (version ${pybind11_VERSION})" "[${pybind11_DIR}][${pybind11_INCLUDE_DIR}]")

find_package(Eigen3 3.2 CONFIG REQUIRED)
find_package_message(EIGEN3 "Found eigen: ${Eigen3_DIR} ${EIGEN3_INCLUDE_DIR} (version ${Eigen3_VERSION})" "[${Eigen3_DIR}][${EIGEN3_INCLUDE_DIR}]")

# find optional dependencies
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})

if (ENABLE_HIP)
    include(HOOMDHIPSetup)
    set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} @CMAKE_CUDA_FLAGS@")
endif()

if (ENABLE_MPI)
    find_dependency(MPI REQUIRED)

    find_package(cereal CONFIG)
    if (cereal_FOUND)
        find_package_message(cereal "Found cereal: ${cereal_DIR}" "[${cereal_DIR}]")

        if (NOT TARGET cereal::cereal AND TARGET cereal)
            message(STATUS "Found cereal target, adding cereal::cereal alias.")
            add_library(cereal::cereal ALIAS cereal)
        endif()
    else()
        # work around missing ceralConfig.cmake (common on Ubuntu 20.04)
        find_path(cereal_INCLUDE_DIR NAMES cereal/cereal.hpp
            PATHS ${CMAKE_INSTALL_PREFIX}/include)
        add_library(cereal::cereal INTERFACE IMPORTED)
        set_target_properties(cereal::cereal PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${cereal_INCLUDE_DIR}")
        find_package_message(cereal "Could not find cereal by config file, falling back to ${cereal_INCLUDE_DIR}" "[${cereal_INCLUDE_DIR}]")
    endif()

    # Work around broken cereal::cereal target (common on Ubuntu 22.04)
    get_target_property(_cereal_include cereal::cereal INTERFACE_INCLUDE_DIRECTORIES)
    if (_cereal_include STREQUAL "/include")
        find_path(cereal_INCLUDE_DIR NAMES cereal/cereal.hpp
            PATHS ${CMAKE_INSTALL_PREFIX}/include)
        set_target_properties(cereal::cereal PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${cereal_INCLUDE_DIR}")
        find_package_message(cereal "Fixing broken cereal::cereal target with ${cereal_INCLUDE_DIR}" "[${cereal_INCLUDE_DIR}]")
    endif()
endif()

include("${CMAKE_CURRENT_LIST_DIR}/hoomd-targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/hoomd-macros.cmake")

check_required_components(HOOMD)
